from timeit import Timer
from Primes import Primes

import sys
import math


def Problem():
    """
    The number, 197, is called a circular prime because all 
    rotations of the digits: 197, 971, and 719, are themselves prime.
    
    There are thirteen such primes below 100: 
    2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
    
    How many circular primes are there below one million?
    """


    primes = Primes(10**6)
    #print primes
    
    def is_circular_prime(x):
        p = str(x)
        for y in range(1,len(p)):
            p = p[-1] + p[:-1]
            if int(p) not in primes:
                del primes[primes.index(x)]
                return False
             
        return True
             
             
    circular = filter(is_circular_prime, primes[:])
    print circular
    
    ans = len(circular)
    print "Answer for Problem 35 = %d" % (ans,)
    
    
if __name__ == "__main__":
    t = Timer(setup='from __main__ import Problem', stmt='Problem()').timeit(1)
    print "Execution time = %0.3f seconds" %(t,)
    